from tool import randomText
import cv2
import os
from config.line_config import Line_CONFIG
root_path = os.getcwd()


class Method():

    def method1(self,img):
        return randomText(["negative", "positive"])
    def method2(self,img):
        return randomText(["negative", "positive"])

method =  Method()

def select(dict_key,img):
    # 根据部件名称选择相应的算法调用
    # method_name =  Line_CONFIG[dict_key]
    # return getattr(method,methodname)(img)

    # 测试阶段随机调用算法
    if dict_key.startswith("A"):
        return getattr(method, 'method1')(img)
    else:
        return getattr(method, 'method2')(img)


def singleScanprocess(img):
    result=[]
    # 考虑对线阵图像进行固定顺序的截取，并采用相应的算法
    img1=img[0:200,300:500]
    img2=img[300:500,0:200]
    img1_result = randomText(["negative", "positive"])
    img2_result = randomText(["negative", "positive"])
    result.append(img1_result)
    result.append(img2_result)
    return result

def CutsingleScan(img,ID):  #根据工单号创建文件夹
    img1 = img[0:20, 20:30]
    img2 = img[0:10, 10:20]
    path = root_path+"/data/" + ID
    if not os.path.exists(path):
        os.makedirs(path)
    cv2.imwrite(path+"/"+"img1.jpg",img1,[int(cv2.IMWRITE_JPEG_QUALITY), 100])
    cv2.imwrite(path+"/"+ "img2.jpg", img2,[int(cv2.IMWRITE_JPEG_QUALITY), 100])


